# coding: utf8
import redis
from libs import myjson as json

pool = redis.ConnectionPool(host='r-uf64cb56d9cbb3d4.redis.rds.aliyuncs.com', password='Huanxi1234', port=6379, db=0, max_connections=200)


# pool = redis.ConnectionPool(host='127.0.0.1', port=6379, db=0, max_connections=200)


def set_session(key, value, time):
    r = redis.Redis(connection_pool=pool)
    r.set(key, json.dumps(value), ex=time)


def very_session(key):
    r = redis.Redis(connection_pool=pool)
    if r.get(key):
        return json.loads(r.get(key))
    else:
        return None


def set_value(key, value, time=None):
    r = redis.Redis(connection_pool=pool)
    r.set(key, json.dumps(value), ex=time)


def get_value(key):
    r = redis.Redis(connection_pool=pool)
    return r.get(key)
